﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhanMemDoVui.BusinessObject;
using PhanMemDoVui.BusinessLogic;

namespace PhanMemDoVui
{
    public partial class frmCreateAccount : Form
    {
        public frmCreateAccount()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.Lamp;
        }

        private void bHighScoreBack_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmWelcome welcome = new frmWelcome();
            welcome.Show();
        }

        private void bCreateAcc_Click(object sender, EventArgs e)
        {
            UserBUS user = UserBUS.Instance();
            Profile pr = new Profile();
            if (txt_name.Text == "" || txt_username.Text == "" || txt_pass.Text == "" || txt_pass_again.Text != txt_pass.Text)
            {
                lab_wrong.Show();
            }
            else if (txt_username.Text.Contains(' ') || txt_username.Text.Length > 10 || txt_pass.Text.Length < 6 || txt_pass.Text.Length > 15 || txt_pass.Text.Contains(' '))
            {
                lab_wrong.Show();
            }
            else
            {
                DialogResult result = MessageBox.Show("Bạn có chắc chắc muốn tạo tài khoản mới?", "Tạo tài khoản", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    pr.Username = txt_username.Text;
                    pr.Password = txt_pass.Text;
                    pr.FullName = txt_name.Text;
                    bool success = user.TaoTaiKhoan(pr);
                    if (success == true)
                    {
                        lab_wrong.Hide();
                        MessageBox.Show("Bạn đã tạo tài khoản thành công", "Tạo tài khoản thành công", MessageBoxButtons.OK);
                        this.Hide();
                        frmWelcome welcome = new frmWelcome();
                        welcome.Show();
                    }
                    else
                    {
                        lab_wrong.Show();
                    }
                }
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void frmCreateAccount_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
